package com.waypolice.manager.controller;

import com.waypolice.base.BaseController;
import com.waypolice.common.pojo.UpmsResult;
import com.waypolice.common.pojo.UpmsResultConstant;
import com.waypolice.manager.service.ArchiveDetailStatisticsService;
import com.waypolice.manager.service.UpmsDictionaryService;
import com.waypolice.manager.service.UpmsOrganizationService;
import com.waypolice.pojo.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by 312小时 on 2019/4/1.
 */
@Controller
@Api(value = "归档明细统计", description = "审计档案归档明细统计")
@RequestMapping(value = "/manage/archiveDetailStatistics")
public class ArchiveDetailStatisticsController extends BaseController{

    private static final Logger LOGGER = LoggerFactory.getLogger(ArchiveDetailStatisticsController.class);


    @Autowired
    private ArchiveDetailStatisticsService archivedetailstatisticsservice;

    @Autowired
    private UpmsOrganizationService upmsOrganizationService;

    @Autowired
    private UpmsDictionaryService upmsDictionaryService;

    @ApiOperation(value = "审计档案归档明细统计首页")
    @RequiresPermissions("cms:archiveDetailStatistics:read")
    @RequestMapping(value = "/index", method = RequestMethod.GET)
    public String index(ModelMap modelMap) {
        List<UpmsOrganization> upmsOrganizations = upmsOrganizationService.selectByExample(new UpmsOrganizationExample());
        List<UpmsDictionary> findAllSecretLevel = upmsDictionaryService.findAllSecretLevel();
        List<UpmsDictionary> storageTime = upmsDictionaryService.findAllStorageTime();
        modelMap.put("upmsOrganizations", upmsOrganizations);
        modelMap.put("secretlevel", findAllSecretLevel);
        modelMap.put("storagetime", storageTime);
        return "/countManager/archivedetailstatistics";
    }

   /* @ApiOperation(value = "搜索条件页")
    @RequiresPermissions("cms:archiveDetailStatistics:read")
    @RequestMapping(value = "/dialog", method = RequestMethod.GET)
    public ModelAndView searchdialog(String flag) {
        ModelAndView mod=new ModelAndView("/countManager/searchdialog");
        mod.addObject("flag",flag);
        return mod;
    }*/


    @ApiOperation(value = "统计明细")
    @RequiresPermissions("cms:archiveDetailStatistics:read")
    @RequestMapping(value = "/detailStatistics")
    @ResponseBody
    public Object detailStatistics( @RequestParam(required = false, defaultValue = "0", value = "offset") int offset,
                                    @RequestParam(required = false, defaultValue = "10", value = "limit") int limit,
                                    @RequestParam(required = false, defaultValue = "", value = "search") String search,
                                    @RequestParam(required = false, value = "sort") String sort,
                                    @RequestParam(required = false, value = "order") String order,
                                    HttpServletRequest request,String flag) {
        Object archiveDetailStatistics = null;
        String vol_archive_unit=request.getParameter("VOL_ARCHIVE_UNIT");
        String vol_archive_year=request.getParameter("VOL_ARCHIVE_YEAR");
        String vol_storage_time=request.getParameter("VOL_STORAGE_TIME");
        String vol_secret=request.getParameter("VOL_SECRET");
        String starttime=request.getParameter("starttime");
        String endtime=request.getParameter("endtime");
        if(null==flag||flag.equals("0")){
            //初始化查询
            archiveDetailStatistics =archivedetailstatisticsservice.getArchiveDetailStatistics(offset, limit);
        }else{
            //条件查询
            archiveDetailStatistics =archivedetailstatisticsservice.getPostArchiveDetailStatistics(offset, limit,vol_archive_unit,vol_archive_year,vol_storage_time,vol_secret,starttime,endtime);
        }
        return archiveDetailStatistics;
    }


}
